/* pixelmerge.cpp - this file is part of PixelMerge
 *
 * Copyright (C) 2010 Pascal Giard
 *
 * Author: Pascal Giard <evilynux@gmail.com>
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Derived from the libwiigui template by Tantric (2009)
 *
 * Top level file - contains main();
 * It loads/saves settings, initialises the Wii and starts up menus.
 */

#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <unistd.h>
#include <wiiuse/wpad.h>
#include <fat.h>

#include "video.h"
#include "audio.h"
#include "menu.h"
#include "input.h"
#include "filelist.h"
#include "FreeTypeGX.h"
#include "pixelmerge.h"

extern "C" {
extern void __exception_setreload(int t);
}

int ExitRequested = 0;
Settings * pxlMgSettings;

void ExitApp() {
  ShutoffRumble();
  StopGX();
  delete pxlMgSettings;
  exit(0);
}

int main(int argc, char *argv[]) {
  __exception_setreload(8); // Reload on crash (after 8 seconds)

  VIDEO_Init(); // Initialize video
  InitVideo();
  SetupPads(); // Initialize input
  InitAudio(); // Initialize audio
  fatInitDefault(); // Initialize file system
  InitFreeType((u8*)font_ttf, font_ttf_size); // Initialize font system
  pxlMgSettings = new Settings(); // Load settings
  InitGUIThreads(); // Initialize GUI

  ResetVideo_Menu(pxlMgSettings->video.offsetX, pxlMgSettings->video.offsetY,
                  pxlMgSettings->video.scaleX, pxlMgSettings->video.scaleY);

  MainMenu(MENU_START);
}
